#include "SpriteSheet.h"

SpriteSheet::SpriteSheet(int numCellsX, int numCellsY)
{
	m_numCellsInX = numCellsX;
	m_numCellsInY = numCellsY;
}

void SpriteSheet::Draw(int x, int y, int cellNum, Screen* theScreen)
{
	// works out width + height of each cell
	// Cell width = witch of image / the number of cells (same for height)
	int cellW = m_surface->w / m_numCellsInX;
	int cellH = m_surface->h / m_numCellsInY;

	// works out cell numbers by the coord of the top-left most pixel
	//cellX = how many pixels along X axis is the start of particular cell
	int cellX = (cellNum % m_numCellsInX) * cellH;
	int cellY = (cellNum / m_numCellsInX) * cellH;

	//used curly braces as SDL written in C so have to initialize in the C way
	SDL_Rect srcRect = {cellX, cellY, cellW, cellH};
	SDL_Rect DestRect = {x, y, 0, 0}; //have to type in same order as in the params

	SDL_BlitSurface(m_surface, &srcRect, theScreen->GetSurface(), &DestRect);
}